package service

import (
	"fiber-demo/internal/global"
	"fiber-demo/internal/model/entity"
)

type UserService struct{}

var UserServiceInstance = UserService{}

func (s UserService) List() (res []entity.User, err error) {
	err = global.DB.Find(&res).Error
	return
}

func (s UserService) One(id int) (res entity.User, err error) {
	err = global.DB.Where(&entity.User{Id: id}).Find(&res).Error
	return
}

func (s UserService) Add(user entity.User) (err error) {
	return global.DB.Create(&user).Error
}

func (s UserService) Modify(user entity.User) (err error) {
	return global.DB.Save(&user).Error
}

func (s UserService) Delete(id int) (err error) {
	return global.DB.Where(&entity.User{Id: id}).Delete(entity.User{}).Error
}
